const { BaseController } = require('../Base')

class Home extends BaseController {
  // 首页导航列表
  homeNavList(ctx) {
    ctx.body = this.resSuccess([
      {
        title: 'home',
        children: [
          { title: '新闻', url: '/news.html' },
          { title: '图片', url: '/img.html' },
          { title: '2048', url: '/game/2048/2048.html' },
          { title: 'snake', url: '/game/snake.html' },
          {
            title: '加解密',
            url: '/cryptoMenu/cryptoMenu.html'
          },
          {
            title: '随机密码',
            url: '/cryptoMenu/randomCrypto/randomCrypto.html'
          }
        ]
      },
      {
        title: 'webpage',
        children: [
          { title: 'memoir', url: '/webpage/memoir/dist/index.html' },
          { title: 'mr', url: '/webpage/mr/dist/index.html' },
          { title: 'mr-admin', url: '/webpage/mr/dist/admin.html' },
          { title: 'resume', url: '/webpage/resume/dist/index.html' },
          { title: 'rich-man', url: '/webpage/rich-man/dist/index.html' }
        ]
      }
    ])
  }
  getWebPage(ctx) {
    const src = this.getSrcPath('public/webpage')
    try {
      this.fs.readdirSync(src)
    } catch (error) {
      // 没有文件夹
      ctx.body = this.resSuccess([])
      return
    }
    const fileList = this.tools.file.getFileFlatList(src)
    const result = fileList
      .filter((e) => e.isFile && e.fileName.endsWith('.html'))
      .map((e) => e.filePath.replace(src.replace(/\\/g, '/'), ''))
    ctx.body = this.resSuccess(result)
  }
}

const ex = new Home()
module.exports = ex
